import java.util.*;

public class Solution2248 {
    public List<Integer> intersection(int[][] nums) {
        Set<Integer> set=new HashSet<>();
        for (int i=0;i<nums[0].length;i++){
            set.add(nums[0][i]);
        }
        for (int i=1;i<nums.length;i++){
            Set<Integer> set1=new HashSet<>();
            for (int j=0;j<nums[i].length;j++){
                if (set.contains(nums[i][j])){
                    set1.add(nums[i][j]);
                }
            }
            set=set1;
        }
        List<Integer> ans=new ArrayList<>(set);
        ans.sort(Comparator.comparingInt(a -> a));
        return ans;
    }

    public static void main(String[] args) {
        System.out.println(new Solution2248().intersection(new int[][]{{3,1,2,4,5},{1,2,3,4},{3,4,5,6}}));
    }
}
